# flask_script与数据库迁移扩展,使之可以在命令行启动
from flask import current_app
from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand
from info import create_app, db


# 通过create_app的方法创建app实例对象,并且传入配置模式:developement
app = create_app('developement')
# 创建Manager对象
manager = Manager(app)
# 创建Migrate对象,使之与app,db关联
Migrate(app, db)
# 添加命令行迁移命令db,db是我们给新命令自己起的名字
manager.add_command('db', MigrateCommand)


@app.route('/')
def index():
    # 演示日志输出
    # import logging
    #
    # logging.debug("This is a debug log.")
    # logging.info("This is a info log.")
    # logging.warning("This is a warning log.")
    # logging.error("This is a error log.")
    # logging.critical("This is a critical log.")
    # 演示flask中日志的输出
    current_app.logger.critical("This is a critical log.")
    # print('abc')
    return 'index'


if __name__ == '__main__':
    # manager只做最基本的启动工作,将app的创建移动到info中的__init__中去


    # 运行开发web服务器
    manager.run()
